package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL删除用户操作
 */
public class Test2 {
    public static void main(String[] args) {
        UserInfo uI = InputUtil.getInputObject(new UserInfo(),"用户删除","删除");
        try(
            Connection con = DBUtil.getConnection();
        ) {
            String sql = "DELETE FROM userinfo " +
                         "WHERE username=?";
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1,uI.getUsername());
            int num = ps.executeUpdate();
            System.out.println("删除"+(num>0?"成功!":"失败!"));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
